#include<iostream>
#include<cmath>
#include<algorithm>
#include<stack>
#define eps 1e-9
using namespace std;
int T,n,m,l,vm,p[100001],an1,an2,f[100001];
struct car{
    int d,v,a,l,r;
    bool operator<(const car t)const{
        if(l==t.l)return r<t.r;
        return l<t.l;
    }
}a[100001];
stack<car>q;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>l>>vm;
        for(int i=1,d,v,ac;i<=n;i++){
            cin>>d>>v>>ac;
            if(ac>0){
                if(v>vm)a[i].l=d;
                if(v*v+2*ac*(l-d)<=vm*vm)a[i].l=l+1;
                else a[i].l=ceil(d+(vm*vm-v*v)*0.5/ac+eps);
                a[i].r=l+1;
            }else if(ac==0){
                if(v>vm)a[i].l=d;
                else a[i].l=l+1;
                a[i].r=l+1;
            }else{
                if(v>vm)a[i].l=d,a[i].r=min(l+1,int(d+(vm*vm-v*v)*0.5/ac-eps));
                else a[i].l=a[i].r=l+1;
            }
            a[i].d=d,a[i].v=v,a[i].a=ac,f[i]=1;
        }
        for(int i=1;i<=m;i++)cin>>p[i];
        an1=an2=0;
        for(int i=1,tr;i<=n;i++){
            a[i].l=lower_bound(p+1,p+m+1,a[i].l)-p,
            tr=int(upper_bound(p+1,p+m+1,a[i].r)-p-1);
            if(tr<a[i].l)a[i].l=a[i].r=m+1;
            else a[i].r=tr;
            if(a[i].l<=m)an1++;
        }
        cout<<an1<<' ';
        random_shuffle(a+1,a+n+1);
        sort(a+1,a+n+1);
        for(int i=1;i<=n;i++){
			if(a[i].l==m+1)break;
            for(int j=1;j<i;j++)
                if(a[j].r<a[i].l)f[i]=max(f[i],f[j]+1);
            an2=max(an2,f[i]);
        }
        /*while(!q.empty())q.pop();
        for(int i=1;i<=n;i++){
            while(!q.empty()&&q.top().r>=a[i].l)q.pop();
            q.push(a[i]);
            an2=max(an2,int(q.size()));
        }*/
        /*for(int i=1,pr;i<=n;){
            pr=a[i].r;
            if(pr==m+1)break;
            an2++;
            while(a[i].l<=pr&&pr<=a[i].r&&i<=n)i++;
        }*/
        cout<<m-an2<<'\n';
    }
	return 0;
}
